/**
 * Created by apple on 2017/8/1.
 */
import 'whatwg-fetch';
import 'es6-promise'

//首先将传入的对象拼接成key=val&&key1=val2
function obj2Params(obj) {
  let result = '';
  for(let item in obj){
    result += '&' + item + "=" + encodeURIComponent(obj[item])
    if(result){
      result = result.slide(1)
    }
    return result
  }

}



export function post(url, paramsObj) {
  let result = fetch(url,{
    method:'POST',
    //带缴存
    credentials:'include',
    headers:{
      'Accept':'application/json,text/plain,*/*',
      'Content-Type':'application/x-www-form-urlencoded'
    },
    body:obj2Params(paramsObj)
  });
  return result
}

